package stu.cms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import stu.cms.pojo.dto.UserDTO;
import stu.cms.pojo.entity.User;
import stu.cms.result.PageResult;
import stu.cms.result.Result;
import stu.cms.service.UserService;

@RestController
@RequestMapping("/user")
@Api(tags ="用户接口")
public class UserController {
    @Autowired
    UserService userService;

    @ApiOperation("分页查询用户")
    @GetMapping("/list")
    public Result<PageResult<User>> getAllUser(UserDTO userDTO) {
        PageResult<User> users = userService.pageSelect(userDTO);
        return Result.success(users);
    }

    @ApiOperation("添加或者修改用户")
    @PostMapping("/save")
    public Result save(@RequestBody User user) {
        userService.saveUser(user);
        return Result.success();
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        userService.removeUser(id);
        return Result.success();
    }


}
